package org.point.controller;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.point.common.controller.BaseController;
import org.point.common.util.DoPage;
import org.point.domain.DeliveryInfo;
import org.point.service.DeliveryInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.alibaba.fastjson.JSONObject;

/**
 * 
 * @ClassName: ConvertRuleDetailController
 * @Description: TODO(收货人信息查询)
 * @author Kenny_Z' szqiuk@gmail.com
 * @date 2016年10月23日 下午9:17:53
 *
 */
@Controller
@RequestMapping("/DeliveryIn/")
public class DeliveryInfoController extends BaseController {
	@Autowired
	private DeliveryInfoService service;

	/**
	 * 
	 * @Title: DeliveryInfoList @Description: TODO(查询收货人信息) @param @param
	 *         userid @param @param currentPage @param @param
	 *         keyWord @param @param response 设定文件 @return void 返回类型 @throws
	 */
	@RequestMapping(value = "DeliveryList.do", method = RequestMethod.POST, produces = "text/plain;charset=UTF-8")
	public void DeliveryList(@RequestParam(value = "userId") String userId,
			@RequestParam(value = "currentPage", required = false) Integer currentPage,
			@RequestParam(value = "keyWord", required = false) String keyWord,
			@RequestParam(value = "status", required = false) String status, HttpServletResponse response) {

		JSONObject jsonObj = new JSONObject();
		DoPage<DeliveryInfo> page = new DoPage<DeliveryInfo>();
		Map<String, Object> map = new HashMap<String, Object>();

		try {
			if (userId != null) {
				map.put("userId", userId);
				page.setPageSize(10);
				if (currentPage != null) {
					page.setCurrentPage(currentPage);
				}
				map.put("firstRecord", page.getFirstRecord());
				map.put("pageSize", page.getPageSize());

				if (strOperateUtil.isNullForString(keyWord)) {
					map.put("keyWord", "%" + keyWord + "%");
				}

				page.setMap(map);
				// 查询积分规则分页数据
				DoPage<DeliveryInfo> resultPage = service.searchDeyForPage(page);
				// 返回分页参数，及积分规则分类数据
				jsonObj.put("page", resultPage);
				// 查询积分规则成功
				jsonObj.put("resultMsg", 1);
			} else {
				// 会员单位ID为null
				jsonObj.put("resultMsg", -1);
			}
		} catch (Exception e) {
			jsonObj.put("resultMsg", 0);
			throw new RuntimeException("查询积分规则分类错误！", e);
		} finally {
			try {
				feedback(response, jsonObj.toString());
			} catch (IOException e) {
				throw new RuntimeException("网络错误，请联系管理员！", e);
			}
		}

	}

}
